Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr: {},
    Number: 1,
    rent:null,
    buy:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(this.data.Number==1){
      var that = this;
      wx.request({
        url: 'https://bag.idianwei.com/index.php/Api/Api/orderList',
        data: {
          userId: 16,
          token: 1501221705,
        },
        success: function (res) {
          console.log(res);
          that.setData({
            arr: res.data.resultObj,
          })
          console.log(that.data.arr);
          for(var i=0;i<that.data.arr.length;i++){
            for (var j = 0; j < that.data.arr[i].goodsInfo.length; j++){
              if (that.data.arr[i].is_sele == "1"){
                var rent=0;
                rent += Number(that.data.arr[i].goodsInfo[j].zu_lenth * that.data.arr[i].goodsInfo[j].zu_money);
                that.setData({
                  rent:rent,
                })
              } else if (that.data.arr[i].is_sele == "2"){
                var buy = 0;
                buy += Number(that.data.arr[i].goodsInfo[j].goodsNums * that.data.arr[i].goodsInfo[j].goodsPrice);
                that.setData({
                  buy: buy,
                })
              }
            }
          }
        }
      })
    }
  },
  jump:function(own){
    console.log(own);
    // var oStr = JSON.stringify(this.data.arr);
    for(var i=0;i<this.data.arr.length;i++){
      var item = this.data.arr[own.currentTarget.dataset.id].orderId;
    }
    wx.navigateTo({
      url: '/pages/index/order_details/order_details?item=' + item + "&id=" + own.currentTarget.dataset.id +"&typeid="+"3",
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  oList:function(own){
    var that=this;
    var switchtype = own.currentTarget.dataset.text;
    console.log(own)
    if (switchtype == 'All1') {
      this.setData({
        Number: 1
      })
      // 待付款
      wx.request({
        url: 'https://bag.idianwei.com/index.php/Api/Api/orderList',
        data: {
          userId: 16,
          token: 1501221705,
        },
        success: function (res) {
          console.log(res);
          that.setData({
            arr: res.data.resultObj,
          })
          console.log(that.data.arr);
          for (var i = 0; i < that.data.arr.length; i++) {
            for (var j = 0; j < that.data.arr[i].goodsInfo.length; j++) {
              if (that.data.arr[i].is_sele == "1") {
                var rent = 0;
                rent += Number(that.data.arr[i].goodsInfo[j].zu_lenth * that.data.arr[i].goodsInfo[j].zu_money);
                that.setData({
                  rent: rent,
                })
              } else if (that.data.arr[i].is_sele == "2") {
                var buy = 0;
                buy += Number(that.data.arr[i].goodsInfo[j].goodsNums * that.data.arr[i].goodsInfo[j].goodsPrice);
                that.setData({
                  buy: buy,
                })
              }
            }
          }
        }
      })
    } else if (switchtype == 'All2') {
      this.setData({
        Number: 2
      })
      // 待付款
      wx.request({
        url: 'https://bag.idianwei.com/index.php/Api/Api/orderList',
        data: {
          userId: 16,
          token: 1501221705,
          orderStatus: -2
        },
        success: function (res) {
          console.log(res);
          that.setData({
            arr: res.data.resultObj,
          })
          console.log(that.data.arr);
        }
      })
    } else if (switchtype == 'All3') {
      this.setData({
        Number: 3
      })
      // 待发货
      wx.request({
        url: 'https://bag.idianwei.com/index.php/Api/Api/orderList',
        data: {
          userId: 16,
          token: 1501221705,
          orderStatus: 0
        },
        success: function (res) {
          console.log(res);
          that.setData({
            arr: res.data.resultObj,
          })
          console.log(that.data.arr);
        }
      })
    } else if (switchtype == 'All4') {
      this.setData({
        Number: 4
      })
      // 已发货
      wx.request({
        url: 'https://bag.idianwei.com/index.php/Api/Api/orderList',
        data: {
          userId: 16,
          token: 1501221705,
          orderStatus: 1
        },
        success: function (res) {
          console.log(res);
          that.setData({
            arr: res.data.resultObj,
          })
          console.log(that.data.arr);
        }
      })
    } else if (switchtype == 'All5') {
      this.setData({
        Number: 5
      })
      //已签收
      wx.request({
        url: 'https://bag.idianwei.com/index.php/Api/Api/orderList',
        data: {
          userId: 16,
          token: 1501221705,
          orderStatus: 4
        },
        success: function (res) {
          console.log(res);
          that.setData({
            arr: res.data.resultObj,
          })
          console.log(that.data.arr);
        }
      })
    } else if (switchtype == 'All6') {
      this.setData({
        Number: 6
      })
      //退款
      wx.request({
        url: 'https://bag.idianwei.com/index.php/Api/Api/orderList',
        data: {
          userId: 16,
          token: 1501221705,
          orderStatus: "-3,-4,-5",
        },
        success: function (res) {
          console.log(res);
          that.setData({
            arr: res.data.resultObj,
          })
          console.log(that.data.arr);
        }
      })
    }
  }
})
